package function;

import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 87111
 * Date: 2025-06-27
 * Time: 21:58
 */
public class DeleteBook implements IWork {
    @Override
    public void work(BookList bookList) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你要删除图书的书名：");
        String name = sc.nextLine();

        int bookSize = bookList.getBookSize();
        for (int i = 0; i < bookSize; i++) {
            if(bookList.getName(i).equals(name)) {
                for (int j = i; j < bookSize - 1; j++) {
                    bookList.setBooks(j,bookList.getBook(j+1));
                }
                bookList.setBooks(bookSize - 1,null);
                bookList.setBookSize(bookList.getBookSize() - 1);
                System.out.println("删除成功");
                return;
            }
        }
        System.out.println("没有这本书");
    }
}
